package com.briup.sms.web.controller;

import com.briup.sms.entity.Shop;
import com.briup.sms.entity.extend.ShopExtend;
import com.briup.sms.service.ShopService;
import com.briup.sms.utils.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author :xuyang
 * @DateTime:2024/1/11 0:06
 * @Version :v1.0.0
 * ClassName:ShopController
 * Package  :com.briup.sms.web.controller
 * Description:TODO
 */
@RestController
@RequestMapping("/shop")
@Api(tags = "商品管理")
@CrossOrigin
public class ShopController {
    @Autowired
    ShopService service;

    @GetMapping("/findShopInfo")
    @ApiOperation("查询所有商品信息")
    @ApiImplicitParams(
            {
                    @ApiImplicitParam(name = "shopName", value = "商品名"),
                    @ApiImplicitParam(name = "pageSize", value = "分页每页数据条数", required = true),
                    @ApiImplicitParam(name = "pageNum", value = "页码", required = true)
            }
    )
    public Result findUserInfo(String shopName, Integer pageSize, Integer pageNum) {
        PageInfo<Shop> shops = service.findShopInfo(shopName, pageSize, pageNum);
        return Result.success(shops);
    }

    @PostMapping("/saveShop")
    @ApiOperation("新增/修改商品信息")
    public Result save(@RequestBody ShopExtend shop) {
        service.save(shop);
        return Result.success();
    }

    @PutMapping("/updateShopStatus/{id}")
    @ApiOperation("修改商品状态")
    public Result updateShopStatus(@PathVariable Integer id) {
        service.updateShopStatus(id);
        return Result.success();
    }

    @GetMapping("/getShopInfo/{id}")
    @ApiOperation("根据id查商品详细信息")
    public Result getShopInfo(@PathVariable Integer id) {
        Shop shop = service.getShopInfo(id);
        return Result.success(shop);
    }
}
